package com.shujia.core

import com.shujia.core.Demo10Join.Student
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo14MapValues {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
    conf.setAppName("Demo14MapValues")
    conf.setMaster("local")

    val sc: SparkContext = new SparkContext(conf)


    // 读取学生数据及分数数据 并将每一行数据转换成样例类对象
    val stuRDD: RDD[(String, String)] = sc
      .textFile("Spark/data/students.txt")
      .map(line => {
        val splits: Array[String] = line.split(",")
        val id: String = splits(0)
        val name: String = splits(1)
        (id, name)
      })

    /**
     * mapValues 转换算子
     * 作用在KV格式的RDD上 可以遍历所有的Values
     */

    stuRDD.mapValues(name => {
      println(name)
    }).foreach(println)


  }

}
